package com.dd.dao.imp;

import com.dd.dao.UsersDao;
import com.dd.domain.Users;
import com.dd.tools.DBHelper;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;

public class UsersDAOImp implements UsersDao {

    private UsersDAOImp(){

    }

    public static UsersDAOImp getInstance(){
        return new UsersDAOImp();
    }

    private String sql = "";
    @Override
    public Users findByUserName(String parUserName){
        sql = "select * from Users where uname = '"+ parUserName +"'";
        List<Map<String,Object>> data = DBHelper.query(sql);
        if(!data.isEmpty()){
            Map<String,Object> row = data.get(0);
            int uid = Integer.parseInt(row.get("uid").toString());
            String uname = row.get("uname").toString();
            String upwd = row.get("upwd").toString();
            Date addtime = (Date)(row.get("addtime"));
            Users users = new Users(uid,uname,upwd,addtime);
            return users;
        }
        return null;
    }
}
